<template>
    <view>
        <!--提示框组件-->
        <u-toast ref="uToast" />
        <view v-if="position && advert">
            <view v-if="position.type==1">
                <view v-for="(item, index) in advert" :key="index">
                    <u--image :showLoading="true" :src="item.imageUrl" mode="widthFix" width="100%" height="auto" @click="showSliderInfo(item.type, item.val)"></u--image>
                </view>
            </view>
            <view v-else>
                <u-swiper :list="advert" indicator indicatorMode="line" circular keyName="imageUrl" :showTitle="showTitle" @click="clickSwiper"></u-swiper>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        props: {
            code: {
                type: String,
                required: true,
                default: 'tpl1_class_banner1'
            },
            showTitle: {
                type: Boolean,
                required: false,
                default: false
            },
        },
        data() {
            return {
                position: {},
                advert: [],
            }
        },
        created() {
            this.getData();
        },
        methods: {
            getData() {
                this.$u.api.advert({
                    code: this.code,
                    platform: 3
                }).then(res => {
                    if (res.status) {
                        this.advert = res.data.childs;
                        this.position = res.data.position;
                        if (this.advert) {
                            for (var i = 0; i < this.advert.length; i++) {
                                this.advert[i].title = this.advert[i].name;
                            }
                        }
                    }
                });
            },
            clickSwiper(index) {
                console.log(index);
                this.showSliderInfo(this.advert[index].type, this.advert[index].val)
            }
        },
    }
</script>
<style scoped lang="scss">
</style>
